package com.ly;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtil {

    public static Connection getConnection(){
        //创建连接
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //设置主机地址
        connectionFactory.setHost("localhost");
        //设置端口
        connectionFactory.setPort(5672);
        //用户名及其密码
        connectionFactory.setUsername("ly");
        connectionFactory.setPassword("123456");
        //设置虚拟主机
        connectionFactory.setVirtualHost("/ly");
        Connection connection = null;
        try {
            connection = connectionFactory.newConnection();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
        return connection;
    }
}
